mui.init({
	swipeBack: true, //启用右滑关闭功能
});

var vm = new Vue({
	el: '#hoems',
	data: {
		list: [],
		books: [],
		imgurl: '',
		notice: [],
		judgeUnReadMessage: ""
	},
		computed: {
		booknum: function() {
			var obj = {
				bookId: "",
				bookName: "暂无数据",
				bookPic: "",
				bookUid: ""
			}
			var num = 4 - this.books.length
			booknum = this.books
			for(var i = 1; i < num; i++) {
				booknum.push(obj)
			}
			return booknum
		}
	}
});

 Vue.use(VueLazyload, {
	             preLoad: 1.3,
	             error: '../../imges/jpimageshomeerrorimage.png',
	             loading: '../../imges/jpimageshomeerrorimage.png'
                      });

mui('.mui-scroll-wrapper').scroll({
	indicators: false, //是否显示滚动条
	bounce: false
});

common.ajax("banner/2", {
	uid: common.uid,
	token: common.token

}, function(data) {

	//	console.log(data)
	if(data.code == 200) {
		vm.list = data.data
		vm.imgurl = data.data[0].url
	} else {
		mui.toast(data.message)
	}
})

common.ajax("student/index/indexRecommend", {
	uid: common.uid,
	token: common.token,
	readState: 1,
	page: 1,
	pageSize: 4
}, function(data) {
	for(var i = 0; i < data.data.length; i++) {
		vm.books.push(data.data[i])
	}
	vm.$nextTick(function() {
		$(".booksimg").height($(".booksimg").find("img").width() * (16 / 12))
	})
}, 'get')

var lunbo = mui('#slider');
lunbo.slider({
	interval: 8000,
});

common.ajax("student/index/notice", {
	uid: common.uid,
	token: common.token
}, function(data) {
	if(data.code == 200) {

		//		for(var i=0; i<data.data.length; i++){
		vm.notice = data.data
		//		}
		vm.$nextTick(function() {
			var lunbo = mui('#slider');
			lunbo.slider({
				interval: 6000,
			});
			var oUl = document.getElementsByTagName('ul')[0];
			//复制两份ul里面的内容到ul中，为的是实现无缝
			oUl.innerHTML = oUl.innerHTML + oUl.innerHTML;
			//计算新的ul的长度
			var temp = 0
			$.each($(".marquee_li"), function() {
				temp += $(this).width()
			});
			$(".marquee_ul").width(temp)
			//设置速度
			var speed = -0.6;

			function move() {
				//向左移动
				if(oUl.offsetLeft < -oUl.offsetWidth / 2) {
					oUl.style.left = '0';
				}
				oUl.style.left = oUl.offsetLeft + speed + 'px';
			}
			var timer = setInterval(move, 18);

		})
	} else {
		mui.toast(data.message)
	}
}, "get")

$(document).on("tap", ".classbooks", function() {
	common.open("../bookdetails/details.html", "../bookdetails/details.html", $(this).attr("bookuid"))
})

$(".read").on("tap", function() {
	location.reload();
})

$(".readsquare").on("tap", function() {
	common.open("../langdu/emptyreading.html")
})

common.clsopen()

common.ajax("student/judgeUnReadMessage", {
	uid: common.uid,
	token: common.token
}, function(data) {
	//	console.log(data.data)
	if(data.code == 200) {
		vm.judgeUnReadMessage = data.data
	} else {
		mui.toast(data.message)
	}
}, "get")

$(document).on("tap", ".more", function() {
	var indexId = plus.webview.getWebviewById('index.html');
	mui.fire(indexId, "gohome");
})